#pragma once
#ifndef RR_CONFIG_H_
#define RR_CONFIG_H_
#include <string>
#include <map>
#include "jgcxtools.h"

using namespace std;

class _DLL_API_ RrConfig
{
public:
	static void Init(string configpath= "config.ini");
	static RrConfig* Get();

public:
	RrConfig()
	{
	}
	~RrConfig()
	{
	}
	bool ReadConfig(const std::string &filename);
	std::string ReadString(const char *section, const char *item, const char *default_value);
	int ReadInt(const char *section, const char *item, const int &default_value);
	float ReadFloat(const char *section, const char *item, const float &default_value);

	void Update(std::string group, std::string key, std::string val);
	void SaveAll();

private:
	bool IsSpace(char c);
	bool IsCommentChar(char c);
	void Trim(std::string &str);
	bool AnalyseLine(const std::string &line, std::string &section, std::string &key, std::string &value);

private:
	// std::map<std::string, std::string> settings_;
	string _configpath;
	std::map<std::string, std::map<std::string, std::string>> settings_;
};

#endif
